using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OracleClient;
using System.Collections.Generic;
using Pms.Utils;
using Biblioteca.Utils;
using Biblioteca.DataBase;
/*
 * 
 * Autor      : Jose Jornando de Carvalho Junior    
 * Data       : 10/04/2010 07:08:44
 * Descricao  : 
 * Alteracoes : 
 * 
 */

namespace SERIX
{
   public class CTiposBeneficiarios
   {
       private string IDT_TPO_BENEF ;
       private string CPF_OBR ;
       private string RG_OBR ;
       private string CERT_OBR ;
       private string DSC_TPO_BENEF ;
       private string PROP_OBR;
       

	   /// <sumary>
       /// Construtor da classe tipos_beneficiarios
       /// <sumary>
       public CTiposBeneficiarios()
       {
   
       }

	   /// <sumary>
       /// Construtor da classe Tipos_beneficiarios
       /// <sumary>
       public CTiposBeneficiarios( string IDT_TPO_BENEF, string CPF_OBR, string RG_OBR, string CERT_OBR, string DSC_TPO_BENEF, string PROP_OBR)
       {
          this.IDT_TPO_BENEF = IDT_TPO_BENEF;
          this.CPF_OBR = CPF_OBR;
          this.RG_OBR = RG_OBR;
          this.CERT_OBR = CERT_OBR;
          this.DSC_TPO_BENEF = DSC_TPO_BENEF;
          this.PROP_OBR = PROP_OBR;       
       }
	   
	   #region Propriedades
     	/// <sumary>
        /// Identificador do tipo de beneficiario
        /// <sumary>
        public string Idt_tpo_benef 
		{
		   get
		   {
		       return this.IDT_TPO_BENEF;
		   }
		   set
		   {
		       this.IDT_TPO_BENEF = value;
		   }
		}
     	/// <sumary>
        /// Indica se o CPF ? obrigatorio do cadastro de beneficiario
        /// <sumary>
        public string Cpf_obr 
		{
		   get
		   {
		       return this.CPF_OBR;
		   }
		   set
		   {
		       this.CPF_OBR = value;
		   }
		}
     	/// <sumary>
        /// Indica se a carteira de identidade e obrigatoria no cadastro de beneficiario
        /// <sumary>
        public string Rg_obr 
		{
		   get
		   {
		       return this.RG_OBR;
		   }
		   set
		   {
		       this.RG_OBR = value;
		   }
		}
     	/// <sumary>
        /// Indica se a certidao de nascimento e obrigatoria no cadastro de beneficiario
        /// <sumary>
        public string Cert_obr 
		{
		   get
		   {
		       return this.CERT_OBR;
		   }
		   set
		   {
		       this.CERT_OBR = value;
		   }
		}
     	/// <sumary>
        /// Descri??o do tipo de beneficiario
        /// <sumary>
        public string Dsc_tpo_benef 
		{
		   get
		   {
		       return this.DSC_TPO_BENEF;
		   }
		   set
		   {
		       this.DSC_TPO_BENEF = value;
		   }
		}
        /// <sumary>
        /// Indica se a propriedade e obrigatoria no cadastro de beneficiario
        /// <sumary>
        public string prop_obr
        {
            get
            {
                return this.PROP_OBR;
            }
            set
            {
                this.PROP_OBR = value;
            }
        }
       
	    #endregion Propriedades
	
	    /// <summary>
        /// Inserindo um novo Tipos_beneficiarios.
        /// </summary>
        public void Inserir(string Login)
        {
		    OracleCommand command = new OracleCommand();
            OracleTransaction trans;

            string SQL = @"insert into Serix.SRX_TIPOS_BENEFICIARIOS
			                  ( IDT_TPO_BENEF, CPF_OBR, RG_OBR, CERT_OBR, DSC_TPO_BENEF, PROP_OBR)
						   values
						      ( :IDT_TPO_BENEF, :CPF_OBR, :RG_OBR, :CERT_OBR, :DSC_TPO_BENEF, :PROP_OBR)";
     		
			try
			{	
				command.Connection = BiblioPMS.ObterConexao(BiblioPMS.aplicacaoSNG, Login, BiblioPMS.Demo);
                trans = command.Connection.BeginTransaction();
                command.Transaction = trans;
                command.CommandType = CommandType.Text;
                command.CommandText = SQL;
				
				command.Parameters.Add(new OracleParameter("IDT_TPO_BENEF",OracleType.Number)); 
				command.Parameters.Add(new OracleParameter("CPF_OBR",OracleType.Char)); 
				command.Parameters.Add(new OracleParameter("RG_OBR",OracleType.Char)); 
				command.Parameters.Add(new OracleParameter("CERT_OBR",OracleType.Char)); 
				command.Parameters.Add(new OracleParameter("DSC_TPO_BENEF",OracleType.VarChar));
                command.Parameters.Add(new OracleParameter("PROP_OBR", OracleType.Char));
                
				
                command.Parameters["IDT_TPO_BENEF"].Value = this.IDT_TPO_BENEF;
                command.Parameters["CPF_OBR"].Value = this.CPF_OBR;
                command.Parameters["RG_OBR"].Value = this.RG_OBR;
                command.Parameters["CERT_OBR"].Value = this.CERT_OBR;
                command.Parameters["DSC_TPO_BENEF"].Value = this.DSC_TPO_BENEF;
                command.Parameters["PROP_OBR"].Value = this.PROP_OBR;
                
				command.ExecuteNonQuery();
                command.Parameters.Clear();
                command.Transaction.Commit();
            }
            catch (Exception e)
            {
                command.Transaction.Rollback();

                if (e is OracleException)
                    throw new Exception(Biblio.ObterMensagem(((OracleException)e).Code, e.Message));
                else
                    throw new Exception(e.Message + " : " + "");
            }
		}
		
	    /// <summary>
        /// Alterando um Tipos_beneficiarios.
        /// </summary>
        public void Alterar(string Login)
        {
		    OracleCommand command = new OracleCommand();
            OracleTransaction trans;

            string SQL = @"update Serix.SRX_TIPOS_BENEFICIARIOS set 
			                   CPF_OBR = :CPF_OBR, RG_OBR = :RG_OBR, CERT_OBR = :CERT_OBR, DSC_TPO_BENEF = :DSC_TPO_BENEF, PROP_OBR = :PROP_OBR
						   where
						       IDT_TPO_BENEF = :IDT_TPO_BENEF ";
     		
			try
			{	
				command.Connection = BiblioPMS.ObterConexao(BiblioPMS.aplicacaoSNG, Login, BiblioPMS.Demo);
                trans = command.Connection.BeginTransaction();
                command.Transaction = trans;
                command.CommandType = CommandType.Text;
                command.CommandText = SQL;
				
				command.Parameters.Add(new OracleParameter("IDT_TPO_BENEF",OracleType.Number)); 
				command.Parameters.Add(new OracleParameter("CPF_OBR",OracleType.Char)); 
				command.Parameters.Add(new OracleParameter("RG_OBR",OracleType.Char)); 
				command.Parameters.Add(new OracleParameter("CERT_OBR",OracleType.Char)); 
				command.Parameters.Add(new OracleParameter("DSC_TPO_BENEF",OracleType.VarChar));
                command.Parameters.Add(new OracleParameter("PROP_OBR", OracleType.Char));
                
				
                command.Parameters["IDT_TPO_BENEF"].Value = this.IDT_TPO_BENEF;
                command.Parameters["CPF_OBR"].Value = this.CPF_OBR;
                command.Parameters["RG_OBR"].Value = this.RG_OBR;
                command.Parameters["CERT_OBR"].Value = this.CERT_OBR;
                command.Parameters["DSC_TPO_BENEF"].Value = this.DSC_TPO_BENEF;
                command.Parameters["PROP_OBR"].Value = this.PROP_OBR;
                
				command.ExecuteNonQuery();
                command.Parameters.Clear();
                command.Transaction.Commit();
            }
            catch (Exception e)
            {
                command.Transaction.Rollback();

                if (e is OracleException)
                    throw new Exception(Biblio.ObterMensagem(((OracleException)e).Code, e.Message));
                else
                    throw new Exception(e.Message + " : " + "");
            }
		}
		
	     /// <summary>
        /// Exclui um  Tipos_beneficiarios.
        /// </summary>
        public void Excluir(string Login)
        {
            Tabela tab = new Tabela("SRX_TIPOS_BENEFICIARIOS", BiblioPMS.ObterConexao(BiblioPMS.aplicacaoSNG, Login,BiblioPMS.Demo));
            tab.adicionarFiltro(new Coluna("IDT_TPO_BENEF", DbType.Int32, this.IDT_TPO_BENEF));
            tab.delete();
        }
		
		static public DataTable ObterTodos(string login)
        {
            
            OracleCommand command = new OracleCommand();

            string SQL = @"select * from Serix.SRX_TIPOS_BENEFICIARIOS order by DSC_TPO_BENEF ";

            try
            {
                command.Connection = BiblioPMS.ObterConexao(BiblioPMS.aplicacaoSNG, login, false);
                command.CommandType = CommandType.Text;
                command.CommandText = SQL;

                DataTable tbl = new DataTable();
                tbl.Load(command.ExecuteReader(CommandBehavior.CloseConnection)); 
                return tbl; 
                
            }
            catch (Exception e)
            {
 
                if (e is OracleException)
                    throw new Exception(Biblio.ObterMensagem(((OracleException)e).Code, e.Message));
                else
                    throw new Exception(e.Message + " : " + "");
            }

        }
		
		static public CTiposBeneficiarios PesquisaporCodigo(string idt_tpo_benef, string login)
        {
            CTiposBeneficiarios obj;
            string SQL = @"SELECT *
                            FROM  Serix.SRX_TIPOS_BENEFICIARIOS 
                            WHERE IDT_TPO_BENEF = :IDT_TPO_BENEF";
            Query qy = null;
            try
            {
                qy = new Query(BiblioPMS.ObterConexao(BiblioPMS.aplicacaoSNG, login, BiblioPMS.Demo), SQL);
				qy.AdicionarParametro(":IDT_TPO_BENEF", DbType.String, idt_tpo_benef);
               
				qy.Executar();
                obj = new CTiposBeneficiarios( qy.ObterCampo("IDT_TPO_BENEF"), qy.ObterCampo("CPF_OBR"), qy.ObterCampo("RG_OBR"), qy.ObterCampo("CERT_OBR"), qy.ObterCampo("DSC_TPO_BENEF"), qy.ObterCampo("PROP_OBR"));
            }                                  
            catch
            {
                if (qy.EstadoConexao() == ConnectionState.Open)
                {
                    qy.FecharConexao();
                }
                return new CTiposBeneficiarios();
            }
			finally
            {
                qy.FecharConexao();
            }
            return obj;
        }
		
		static public int ObterNovoIdt(string login)
        {
            string SQL = @"SELECT PKG_BIBSERIX.OBTER_IDT_TPO_BENEF() IDT From dual ";
            Query qy = null;
            try
            {
                qy = new Query(BiblioPMS.ObterConexao(BiblioPMS.aplicacaoSNG, login, BiblioPMS.Demo), SQL);
				qy.Executar();
				return Convert.ToInt32(qy.ObterCampo("IDT"));
            }
            catch
            {
                if (qy.EstadoConexao() == ConnectionState.Open)
                {
                    qy.FecharConexao();
                }
                return-1;
            }
			finally
            {
                qy.FecharConexao();
            }
        }
		
    }
}	

